package loadvideo;

import android.os.AsyncTask;

import org.json.JSONException;

import java.io.IOException;
import java.util.List;

/**
 * Created by Administrator on 2016/9/11.
 */
public class DownloadTask extends AsyncTask<String,Void,List<Video>> {

    public interface OnMovieByPathListener{
        void setOnMovieByPath(List<Video> data);
    }

    private OnMovieByPathListener mListener;
    public DownloadTask(OnMovieByPathListener listener){
        this.mListener=listener;
    }

    @Override
    protected List<Video> doInBackground(String... params) {
        try {
            byte[] jsonByte = HttpUtilVideo.getJsonByPath(params[0]);
            List<Video> videos = HttpUtilVideo.getMsgbyJson(new String(jsonByte,0,jsonByte.length));
            return videos;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(List<Video> videos) {
        super.onPostExecute(videos);

        mListener.setOnMovieByPath(videos);
    }
}
